<?php
/**
 *
 * 版权所有：恰维网络<qwadmin.qiawei.com>
 * 作    者：寒川<hanchuan@qiawei.com>
 * 日    期：2016-01-21
 * 版    本：1.0.0
 * 功能说明：前台控制器演示。
 *
 **/
namespace Api\Controller;

class UserController extends ComController
{
    /**
     * 检测用户是否已经登录
     */
    public function check_login()
    {
        $r['code'] = 0;
        $r['msg']  = '未登录';
        $r['data'] = '';
        if(session('phone')){
            $r['code'] = 1;
            $r['msg']  = '已登录';
            $r['data'] = array('phone',session('phone'));
        }
        echo json_encode($r,JSON_UNESCAPED_UNICODE);
    }

    /**
     * 用户登录 手机银行 将返回值 存入数据库中
     */
    public function login_insert()
    {
        $phone = I('post.phone');
        $username = I('post.username');
        $id_card = I('post.id_card');

        session('phone',$phone);

        $user = M('user');

        $where['phone'] = $phone;
        $count = $user->where($where)->count();
        if($count < 1){

            $data['phone']      = $phone;
            $data['username']   = $username;
            $data['id_card']    = $id_card;
            $data['add_time']   = time();

            $user->add($data);
        }
        $r['code'] = 1;
        $r['msg']  = '登录成功';
        $r['data'] = array('phone',session('phone'));
        
        echo json_encode($r,JSON_UNESCAPED_UNICODE);
    }


    public function login()
    {
        $this->display();
    }



}